<?php

class Form extends Controller {

        function Form()
        {
                parent::Controller();
        }

        function reg_form()
        {
            $this->load->library('form_validation');

            if ($this->input->post('name'))
                {
                        //Validate & Prep
                        $this->form_validation->set_rules('name', 'Name Field', 'trim|required|max_length[15]');
                        $this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email');
                        $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|max_length[50]');
                        $this->form_validation->set_rules('pass_2', 'Confirmation', 'required|matches[password]');
                        $result = $this->form_validation->run();

                        if ($result == TRUE)
                        {
                            $this->load->model('add_model');
                            $result = $this->add_model->add_user($_POST['name'], $_POST['email'], $_POST['password']);

                            if ($result === TRUE){
                                $this->load->controller('user');
                                $this->load->user->user_page();
                            }
                            else{
                                echo "Problem adding you as a user.";
                                $this->load->view('register_view');
                            }

                        }
                        else
                        {
                            echo "There were errors with your submission!";
                            echo "<p>" . validation_errors() . "</p>";
                        }
                }

                $this->load->view('register_view');

        }

}
//EOF
